cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA19.log", replace

clear all
set more off

mat TableA19 = J(9, 3, -9)

use "RawData/anes_timeseries_cdf.dta", clear

tab VCF0004
keep if (VCF0004 >= 1970 & VCF0004 <= 2000) | VCF0004 == 2004 | VCF0004 == 2012

forvalues i = 1972(2)2000 {
gen yeardum`i'= (VCF0004  == `i')
}
gen yeardum2004 = (VCF0004 == 2004)
gen yeardum2012 = (VCF0004 == 2012)

// Party Identification (Leaners = Independents)

tab VCF0301
tab VCF0301 VCF0004

gen partyid = 0 if VCF0301 == 1 
replace partyid = 0 if VCF0301 == 2 
replace partyid = 1/2 if VCF0301 == 3
replace partyid = 1/2 if VCF0301 == 4 
replace partyid = 1/2 if VCF0301 == 5
replace partyid = 1 if VCF0301 == 6 
replace partyid = 1 if VCF0301 == 7 

// Gender 

tab VCF0104 
gen female = (VCF0104 == 2)

forvalues i = 1972(2)2000 {
gen femaleXyeardum`i'= female * (VCF0004  == `i')
}
gen femaleXyeardum2004 = female * (VCF0004 == 2004)
gen femaleXyeardum2012 = female * (VCF0004 == 2012)

// College

tab VCF0110 VCF0004
gen college = (VCF0110 == 4)
replace college = . if VCF0110 == 0
gen femaleXcollege = female * college

//
// Differences in Party Issue Positions
//

// Govt Health Insurance Scale
local variable1 = "VCF0508"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0509"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem1 = `variable2' - `variable1'

// Guaranteed Jobs Scale
local variable1 = "VCF0513"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0514"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem2 = `variable2' - `variable1'

// Aid to Blacks Scale
local variable1 = "VCF0517"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0518"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem3 = `variable2' - `variable1'

// Rights of Accused Scale
local variable1 = "VCF0524"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0525"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem4 = `variable2' - `variable1'

// Urban Unrest Scale
local variable1 = "VCF0528"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0529"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem5 = `variable2' - `variable1'

// Aid to Blacks Scale
local variable1 = "VCF0533"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0534"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem6 = `variable2' - `variable1'

// Gender Roles
local variable1 = "VCF0537"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0538"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem7 = `variable2' - `variable1'

// Govt Services/Spending Scale
local variable1 = "VCF0541"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0542"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem8 = `variable1' - `variable2'  

// Cooperation with U.S.S.R. Scale
local variable1 = "VCF0545"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0546"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem9 = `variable2' - `variable1'

// Defense Spending Scale 
local variable1 = "VCF0549"
tab `variable1'
replace `variable1' = . if `variable1' == 0 | `variable1' == 8 | `variable1' == 9
replace `variable1' = (`variable1' - 1) / 6
local variable2 = "VCF0550"
tab `variable2'
replace `variable2' = . if `variable2' == 0 | `variable2' == 8 | `variable2' == 9
replace `variable2' = (`variable2' - 1) / 6
gen repminusdem10 = `variable2' - `variable1'

forvalues i = 1(1)10 {
tab repminusdem`i' VCF0004
}

egen avgrepminusdem = rmean(repminusdem1-repminusdem10)
gen missingavgrepminusdem = missing(avgrepminusdem)

sum avgrepminusdem
gen femaleXavgrepminusdem = female * avgrepminusdem

// Drops observations w/ missing college or issue positions
drop if missing(college) | missing(avgrepminusdem)

// College Only

local column = 1
regress partyid female college femaleXcollege yeardum* femaleXyeardum* [pweight = VCF0009z], robust
mat TableA19[1, `column'] = _b[college]
mat TableA19[2, `column'] = -_se[college]
mat TableA19[3, `column'] = _b[femaleXcollege]
mat TableA19[4, `column'] = -_se[femaleXcollege]
mat TableA19[9, `column'] = e(N)

lincom _b[female] + _b[femaleXcollege]

// Polarization Only

local column = 2

regress partyid female avgrepminusdem femaleXavgrepminusdem yeardum* femaleXyeardum* [pweight = VCF0009z], robust
mat TableA19[5, `column'] = _b[avgrepminusdem]
mat TableA19[6, `column'] = -_se[avgrepminusdem]
mat TableA19[7, `column'] = _b[femaleXavgrepminusdem]
mat TableA19[8, `column'] = -_se[femaleXavgrepminusdem]
mat TableA19[9, `column'] = e(N)

centile avgrepminusdem, centile(25 50 75)
scalar c75 = r(c_3) 
scalar c50 = r(c_2)
scalar c25 = r(c_1)

lincom _b[female]
lincom _b[female] + _b[femaleXavgrepminusdem]*c25
lincom _b[female] + _b[femaleXavgrepminusdem]*c50
lincom _b[female] + _b[femaleXavgrepminusdem]*c75
lincom _b[female] + _b[femaleXavgrepminusdem]

// Combined

local column = 3

regress partyid female college femaleXcollege avgrepminusdem femaleXavgrepminusdem yeardum* femaleXyeardum* [pweight = VCF0009z], robust
mat TableA19[1, `column'] = _b[college]
mat TableA19[2, `column'] = -_se[college]
mat TableA19[3, `column'] = _b[femaleXcollege]
mat TableA19[4, `column'] = -_se[femaleXcollege]
mat TableA19[5, `column'] = _b[avgrepminusdem]
mat TableA19[6, `column'] = -_se[avgrepminusdem]
mat TableA19[7, `column'] = _b[femaleXavgrepminusdem]
mat TableA19[8, `column'] = -_se[femaleXavgrepminusdem]
mat TableA19[9, `column'] = e(N)

centile avgrepminusdem, centile(25 50 75)
scalar c75 = r(c_3) 
scalar c50 = r(c_2)
scalar c25 = r(c_1)

lincom _b[female]
lincom _b[female] + _b[femaleXavgrepminusdem]*c25
lincom _b[female] + _b[femaleXavgrepminusdem]*c50
lincom _b[female] + _b[femaleXavgrepminusdem]*c75
lincom _b[female] + _b[femaleXavgrepminusdem]

lincom _b[female] + _b[femaleXcollege]

matlist TableA19

log close
